<%@ page pageEncoding="utf-8" isELIgnored="false" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>校园超市管理系统</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/jsp/css/public.css"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/jsp/css/style.css"/>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/js/easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/js/easyui/themes/icon.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/jsp/js/bootstrap/css/bootstrap.min.css"/>
    <script type="text/javascript" src="${pageContext.request.contextPath}/jsp/js/jQuery1.11.1.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/easyui/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/easyui/jquery.easyui.min.js"></script>
    <%--  <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.pagination.js"></script>--%>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/easyui/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript">
        jQuery.noConflict();
        var  loginOut;
        var del;//删除用户
        var  update;
        var  daochu;
        jQuery(function($){
            var  name=$("#userName").val();
            daochu=function daochuuser() {
                $.ajax({
                    url:"${pageContext.request.contextPath}/downloadFile",
                    type:"post",
                    data:{"username":name},
                    statusCode: {
                        403: function() {
                            $.messager.alert("温馨提示","对不起，您无权访问","error");
                            //window.location.href = "login.html";
                        }
                    },
                    success:function (data) {
                        location.href="${pageContext.request.contextPath}/jsp/"+data.data+".jsp"
                    }
                });
            }
            update=function updateuser() {
                var i=$("#checkboxs:checked").length;
                if(i>1){
                   $.messager.alert("温馨提示","只能选择一项","question");
                }else if(i<1){
                    $.messager.alert("温馨提示","请选择一项","question");
                }else{
                    location.href="${pageContext.request.contextPath}/updateuser?id="+$("#checkboxs:checked").val();
                }
            }
            del=function deluser() {
                var check = $("#checkboxs:checked").length;
                var  ids="";
                if (check==0){
                   $.messager.alert("温馨提示","请选择要删除的选项","question");
                }else{
                    $.messager.confirm("温馨提示","确认要删除吗？",function (r) {
                        if (r){
                            var checkboxs=$("#checkboxs:checked");
                            for(var i=0;i<checkboxs.length;i++){
                                ids+=checkboxs[i].value+',';
                            }
                            $.ajax({
                                url:"${pageContext.request.contextPath}/deleteuser",
                                type:"post",
                                data:{"str":ids},
                                statusCode: {
                                    403: function() {
                                        $.messager.alert("温馨提示","对不起，您无权访问","error");
                                    }
                                },
                                success:function (data) {
                                    if (data=="true"){
                                        var win = $.messager.progress({
                                            title:'温馨提示',
                                            msg:'正在删除...'
                                        });
                                        setTimeout(function(){
                                            $.messager.progress('close');
                                            $.messager.show({
                                                title:'温馨提示',
                                                msg:'删除成功',
                                                showType:'show'
                                            });
                                        },1500);
                                        setTimeout(function(){
                                            location.href="${pageContext.request.contextPath}/showUserList";
                                        },3000);
                                    }
                                    else{
                                        $.messager.alert("温馨提示","删除失败","error");
                                    }
                                }
                            });
                        }else{
                            return false;
                        }
                    });


                }

            }
            var  name;
            //加载数据
            $("#btn").click(function () {
                 name  =$("#userName").val();
                load(0,5);
            });
            load(0,5);

            function  load(index,PageSize) {
                $.ajax({
                    url:"${pageContext.request.contextPath}/userInfo",
                    type:"post",
                    data:{"PageIndex":index,"PageSize":PageSize,"userName":name},
                    statusCode: {
                        403: function() {
                            $.messager.alert("温馨提示","对不起，您无权访问","error");
                        }
                    },
                    success:function (data) {
                        //模拟ajax去后端读取页数，获取数据并渲染列表的过程
                        $('#list-content').html('');
                        $.each(data.data.list,function (i, item) {
                            $("#list-content").append("<tr><td><input name='checkboxs' type='checkbox' id='checkboxs' value="+item.id+"></td><td>"+item.userCode+"</td><td>"+item.userName+
                                "</td><td>"+item.gendername+"</td><td>"+item.age+"</td><td>"+item.phone+"</td><td>"
                                +item.role.name+"</td></td>");
                        })
                        //渲染分页

                        if(data.data.totalRecords>0){
                            $('#pagination').pagination({
                                total:data.data.totalRecords,//总记录数
                                pageSize:PageSize,//页面大小
                                pageNumber:index+1,//当前页码
                                pageList: [5, 10, 15], //5表示页显示5条数据。10条是每页显示10条数据  15表示每页显示15条数据
                                onSelectPage:function(pageNumber,PageSize){
                                    load(pageNumber-1,PageSize);
                                }
                            });

                        }else{
                            $('#pagination').html("<span style='color:red;font-size: 18px'>没有检索到结果~~~~~！！！！！！</span>");
                        }
                    }
                });
            }

            loginOut=function userLoginOut() {
                $.messager.confirm("温馨提示", "确定要退出吗？", function (r) {
                    if (r) {
                        location.href="${pageContext.request.contextPath}/loginout";
                    } else {
                        return false;
                    }

                });
            }
        });

    </script>
</head>
<body>
<!--头部-->
    <header class="publicHeader">
        <h1>校园超市管理系统</h1>
        <div class="publicHeaderR">
            <p><span>您好！</span><span style="color: #fff21b">${keyword} ${login}</span> , 欢迎你！</p>
            <%--<a href="${pageContext.request.contextPath}/loginout">退出</a>--%>
        </div>
    </header>
<!--时间-->
    <section class="publicTime">
        <span id="time">2015年1月1日 11:11  星期一</span>
        <a href="#">温馨提示：为了能正常浏览，请使用高版本浏览器！（IE10+）</a>
    </section>
<!--主体内容-->
    <section class="publicMian ">
        <div class="left">
            <h2 class="leftH2">
                <%--<span class="span1">--%>

                <%--</span>--%>
                <span class="span_gn">功能列表</span>
            </h2>
            <nav>
                <ul class="list">
                    <li><a href="${pageContext.request.contextPath}/jsp/productList.jsp">商品管理</a></li>
                    <li><a href="${pageContext.request.contextPath}/jsp/billList.jsp">订单管理</a></li>
                    <li><a href="${pageContext.request.contextPath}/jsp/providerList.jsp">供应商管理</a></li>
                    <li id="active"><a href="${pageContext.request.contextPath}/showUserList">用户管理</a></li>
                    <li><a href="${pageContext.request.contextPath}/jsp/password.jsp">密码修改</a></li>
                    <li><a onclick="loginOut()">退出系统</a></li>
                </ul>
            </nav>
        </div>
        <div class="right">
            <div class="location">
                <strong>你现在所在的位置是:</strong>
                <span>用户管理页面</span>
            </div>
            <div class="search">
                <span>用户名：</span>
                    <input type="text" id="userName" name="userName" placeholder="请输入用户名"/>
                    <input type="button"  id="btn" value="查询"/>
                <div class="searchText">
                    <a href="${pageContext.request.contextPath}/jsp/userAdd.jsp">添加用户</a>
                    <a onclick="return update()">修改用户</a>
                    <a  onclick="return del()">删除用户</a>
                    <a  href="${pageContext.request.contextPath}/jsp/echarts.jsp">数据展示</a>
                <a onclick="daochu()">导出用户</a>
                </div>
            </div>
            <!--用户-->
            <table class="providerTable" cellpadding="0" cellspacing="0">
                <tr class="firstTr">
                    <th width="10%">请选择</th>
                    <th width="10%">用户编码</th>
                    <th width="20%">用户名称</th>
                    <th width="10%">性别</th>
                    <th width="10%">年龄</th>
                    <th width="10%">电话</th>
                    <th width="10%">用户类型</th>
                </tr>
               <tbody id="list-content"></tbody>
            </table>
            <div class="pagination" id="pagination" style="margin:4px 0 0 0"></div>

        </div>
    </section>

<!--点击删除按钮后弹出的页面-->
<div class="zhezhao"></div>
<div class="remove" id="removeUse">
    <div class="removerChid">
        <h2>提示</h2>
        <div class="removeMain">
            <p>你确定要删除该用户吗？</p>
            <a href="#" id="yes">确定</a>
            <a href="#" id="no">取消</a>
        </div>
    </div>
</div>

    <footer class="footer">
        版权归本超市所有
    </footer>
<script src="${pageContext.request.contextPath}/jsp/js/jquery.js"></script>
<script src="${pageContext.request.contextPath}/jsp/js/js.js"></script>
<script src="${pageContext.request.contextPath}/jsp/js/time.js"></script>
</body>
</html>